package ru.pb.game.data.scripts;

import java.lang.reflect.Modifier;

import org.apache.log4j.Logger;

/**
 * @author Felixx
 * @param <T>
 */
public class ScriptClass<T>
{
	private static final Logger _log = Logger.getLogger(ScriptClass.class);
	private final Class<T> _class;

	public ScriptClass(Class<T> c)
	{
		_class = c;
	}

	public ScriptInstance newInstance()
	{
		try
		{
			if(_class.getConstructor() != null && !Modifier.isAbstract(_class.getModifiers()))
			{

				T obj = _class.newInstance();
				return new ScriptInstance<T>(_class, obj);
			}
		}
		catch(NoSuchMethodException ignored)
		{}
		catch(Exception e)
		{
			_log.info("Exception: in class" + _class.getSimpleName() + " " + e, e);
		}

		return null;
	}

	public Class<T> getSourceClass()
	{
		return _class;
	}
}